# 定义正则转换器
from flask import session, g, jsonify
from werkzeug.routing import BaseConverter
from functools import wraps

from ihome.utils.response_code import RET


class ReConverter(BaseConverter):
    """"""
    def __init__(self, url_map, regex):
        super(ReConverter, self).__init__(url_map)
        self.regex = regex


def login_required(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        user_id = session.get('user_id')
        if user_id:
            g.user_id = user_id
            return fn(*args, **kwargs)
        return jsonify(errno=RET.SESSIONERR, errmsg="没有获取session数据")
    return wrapper
